package com.ruoyi.pdf.controller;

import java.util.Date;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.pdf.domain.BusinessPdf;
import com.ruoyi.pdf.service.IBusinessPdfService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * pdf的增删改查Controller
 *
 * @author anjie
 * @date 2020-06-01
 */
@Controller
@RequestMapping("/pdf/pdf")
public class BusinessPdfController extends BaseController
{
    private String prefix = "pdf/pdf";

    @Autowired
    private IBusinessPdfService businessPdfService;

    @RequiresPermissions("pdf:pdf:view")
    @GetMapping()
    public String pdf()
    {
        return prefix + "/pdf";
    }

    /**
     * 查询pdf的增删改查列表
     */
    @RequiresPermissions("pdf:pdf:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BusinessPdf businessPdf)
    {
        startPage();
        List<BusinessPdf> list = businessPdfService.selectBusinessPdfList(businessPdf);
        return getDataTable(list);
    }

    /**
     * 导出pdf的增删改查列表
     */
    @RequiresPermissions("pdf:pdf:export")
    @Log(title = "pdf的增删改查", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BusinessPdf businessPdf)
    {
        List<BusinessPdf> list = businessPdfService.selectBusinessPdfList(businessPdf);
        ExcelUtil<BusinessPdf> util = new ExcelUtil<BusinessPdf>(BusinessPdf.class);
        return util.exportExcel(list, "pdf");
    }

    /**
     * 新增pdf的增删改查
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存pdf的增删改查
     */
    @RequiresPermissions("pdf:pdf:add")
    @Log(title = "pdf的增删改查", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BusinessPdf businessPdf)
    {
        return toAjax(businessPdfService.insertBusinessPdf(businessPdf));
    }

    /**
     * 修改pdf的增删改查
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        BusinessPdf businessPdf = businessPdfService.selectBusinessPdfById(id);
        mmap.put("businessPdf", businessPdf);
        return prefix + "/edit";
    }

    /**
     * 修改保存pdf的增删改查
     */
    @RequiresPermissions("pdf:pdf:edit")
    @Log(title = "pdf的增删改查", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BusinessPdf businessPdf) {
        businessPdf.setUpdateTime(new Date());
        return toAjax(businessPdfService.updateBusinessPdf(businessPdf));
    }

    /**
     * 删除pdf的增删改查
     */
    @RequiresPermissions("pdf:pdf:remove")
    @Log(title = "pdf的增删改查", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(businessPdfService.deleteBusinessPdfByIds(ids));
    }
}
